import { post, fileGet, get, postFormData, filePost } from '../../http'
import store from '@/store'

/**
 *
 * @param {*} data
 */
export const addContractModel = data => {
  data.fltId = store.state.user.FLT_UUID_DX_H
  data.creator = store.state.user.USR_CODE_DX_H
  data.dptId = store.state.user.DPTID_DX_H
  return post('/FTKJWLHYPT/contract/add', {
    Data: {
      Parameters: {
        FTKJWLHYPT: data,
      },
    },
  })
}

export const downloadContractModel = data => {
  return fileGet('/FTKJWLHYPT/contract/download', data)
}

export const downloadContractHtmlModel = data => {
  return get('/FTKJWLHYPT/contract/downloadHtml', data)
}
export const delContractModel = data => {
  data.fltId = store.state.user.FLT_UUID_DX_H
  data.editor = store.state.user.USR_CODE_DX_H
  data.dptId = store.state.user.DPTID_DX_H
  return post('/FTKJWLHYPT/contract/del', {
    Data: {
      Parameters: {
        FTKJWLHYPT: data,
      },
    },
  })
}

export const editContractModel = data => {
  data.fltId = store.state.user.FLT_UUID_DX_H
  data.editor = store.state.user.USR_CODE_DX_H
  data.dptId = store.state.user.DPTID_DX_H
  return post('/FTKJWLHYPT/contract/update', {
    Data: {
      Parameters: {
        FTKJWLHYPT: data,
      },
    },
  })
}

// export const contractGenerateNo = (data) => {
//   return post('/FTKJWLHYPT/contract/generateNo', {
//     Data: {
//       Parameters: {
//         FTKJWLHYPT: data
//       }
//     }
//   })
// }
export const contractGenerateNo = data => {
  return post('/FTKJWLHYPT/contract/createNo', {
    Data: {
      Parameters: {
        FTKJWLHYPT: data,
      },
    },
  })
}
//修改运输单价
export const updatePrice = (cmtId, cmtTransportUnitPrice) => {
  return post('/FTKJWLHYPT/contract/updatePrice', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cmtId,
          cmtTransportUnitPrice,
        },
      },
    },
  })
}
export const findBidingModel = bidId => {
  return post('/FTKJWLHYPT/bidding/queryContractInfo', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bidId,
        },
      },
    },
  })
}

export const contractBidding = data => {
  return post('/FTKJWLHYPT/bidding/queryContractBidding', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bidCode: data.bidCode,
          bidName: data.bidName,
          carrierId: store.state.user.FLT_UUID_DX_H,
        },
      },
    },
  })
}

export const effective = (cmtId, cmtTransportUnitPrice) => {
  return post('/FTKJWLHYPT/contract/effective', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cmtId,
          cmtTransportUnitPrice,
          cmtSigningLaster: store.state.user.USR_CODE_DX_H,
        },
      },
    },
  })
}
//驳回
export const updateback = cmtId => {
  return post('/FTKJWLHYPT/contract/doback', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cmtId,
        },
      },
    },
  })
}
//文件列表
export const getFileList = data => {
  return post('/FTKJWLHYPT/common/viewFile', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          pubId: data.pubId,
          module: data.module,
        },
      },
    },
  })
}
//删除文件
export const delFile = data => {
  return post('/FTKJWLHYPT/common/deleteFile', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          aId: data.aId,
        },
      },
    },
  })
}

export const contractSugar = (bidId, demandCode) => {
  return post('/FTKJWLHYPT/bidding/queryContractSugar', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          bidId,
          demandCode,
        },
      },
    },
  })
}
//目的地收货方或者收货联系人或者联系人电话
export const dropdownsh = data => {
  return post('/FTKJWLHYPT/contract/selectPlaceOrPhoneOrPeople', {
    Data: {
      Parameters: {
        FTKJWLHYPT: data,
      },
    },
  })
}

//根据目的地收货方查询收货联系人或者联系人电话
export const phoneOrpeople = data => {
  return post('/FTKJWLHYPT/contract/selectPhoneOrPeople', {
    Data: {
      Parameters: {
        FTKJWLHYPT: data,
      },
    },
  })
}

//甲方下拉
export const findjfang = () => {
  return post('/FTKJWLHYPT/dropDown/findDrowDrowdownSugar', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {},
      },
    },
  })
}
//甲方类型
export const findjfangType = data => {
  return post('/FTKJWLHYPT/dropDown/findKhtype', {
    Data: {
      Parameters: {
        FTKJWLHYPT: data,
      },
    },
  })
}

//乙方下拉
export const findefang = () => {
  return post('/FTKJWLHYPT/dropDown/findDrowDrowdownGys', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {},
      },
    },
  })
}
//查询
export const findContractModel = data => {
  data.fltId = store.state.user.FLT_UUID_DX_H
  data.dptId = store.state.user.DPTID_DX_H
  return post('/FTKJWLHYPT/contract/findListPage', {
    Data: {
      Parameters: {
        FTKJWLHYPT: data,
      },
      Orderbys: {},
      PageIndex: {
        FTKJWLHYPT: data.currentPage,
      },
      PageSize: {
        FTKJWLHYPT: data.pageSize,
      },
    },
  })
}
//查询
export const findContractModel2 = data => {
  data.fltId = null
  data.dptId = null
  return post('/FTKJWLHYPT/contract/findListPage1', {
    Data: {
      Parameters: {
        FTKJWLHYPT: data,
      },
      Orderbys: {},
      PageIndex: {
        FTKJWLHYPT: data.currentPage,
      },
      PageSize: {
        FTKJWLHYPT: data.pageSize,
      },
    },
  })
}

//查询货主与平台的签订状态
export const findStats = data => {
  return post('/FTKJWLHYPT/contract/findstats', {
    Data: {
      Parameters: {
        FTKJWLHYPT: data,
      },
    },
  })
}
//查询已签订的
export const findContractModel1 = data => {
  data.fltId = -1
  data.dptId = store.state.user.DPTID_DX_H
  return post('/FTKJWLHYPT/contract/findListexpire', {
    Data: {
      Parameters: {
        FTKJWLHYPT: data,
      },
      Orderbys: {},
      PageIndex: {
        FTKJWLHYPT: data.currentPage,
      },
      PageSize: {
        FTKJWLHYPT: data.pageSize,
      },
    },
  })
}
//每日吨量
export const countTonsDay = data => {
  return post('/FTKJWLHYPT/contract/countTonsDay', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cmtPartyA: store.state.user.DPTID_DX_H,
          cmtPartyB: store.state.user.FLT_UUID_DX_H,
        },
      },
    },
  })
}

//每日吨量
export const selectSysCompanyByFltName = data => {
  return post('/FTKJWLHYPT/base/selectSysCompanyByFltName', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          fltName: data.fltName,
        },
      },
    },
  })
}
// //每月吨量
// export const countTonsMonth = (data) => {
//   return post('/FTKJWLHYPT/contract/countTonsMonth',
//     {
//       Data:
//       {
//         Parameters:
//         {
//           FTKJWLHYPT:
//           {
//             cmtPartyA : store.state.user.DPTID_DX_H,
//             cmtPartyB : store.state.user.FLT_UUID_DX_H,
//             // cmtPartyA: store.state.user.DPTID_DX_H
//           }
//         }
//       }
//     });
// }
// //每年吨量
// export const countTonsYear = (data) => {
//   return post('/FTKJWLHYPT/contract/countTonsYear',
//     {
//       Data:
//       {
//         Parameters:
//         {
//           FTKJWLHYPT:
//           {
//             cmtPartyA : store.state.user.DPTID_DX_H,
//             cmtPartyB : store.state.user.FLT_UUID_DX_H,
//           }
//         }
//       }
//     });
// }
// //总吨量
// export const countTonsAll = (data) => {
//   return post('/FTKJWLHYPT/contract/countTonsAll',
//     {
//       Data:
//       {
//         Parameters:
//         {
//           FTKJWLHYPT:
//           {
//             cmtPartyA : store.state.user.DPTID_DX_H,
//             cmtPartyB : store.state.user.FLT_UUID_DX_H,
//           }
//         }
//       }
//     });
// }

//平台发起合同终止
export const terminationContract = ({ cmtId, cmtContractState, weightEnd }) => {
  return post('/FTKJWLHYPT/contract/terminationContract', {
    Data: {
      Parameters: {
        FTKJWLHYPT: {
          cmtId,
          cmtContractState,
          weightEnd,
        },
      },
    },
  })
}

//合同导出
export const exportContract = data => {
  return filePost('/FTKJWLHYPT/contract/exportContract', {
    Data: {
      Parameters: {
        FTKJWLHYPT: data,
      },
    },
  })
}
